# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=transmission
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.94
pkgrel=2
pkgdesc="Fast, easy, and free BitTorrent client (mingw-w64)"
arch=('any')
url='https://www.transmissionbt.com/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-libevent"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-miniupnpc")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip' 'staticlibs')
source=("https://github.com/transmission/transmission-releases/raw/master/transmission-${pkgver}.tar.xz"
        "skip-broken-cmake-rc.patch")
sha256sums=('35442cc849f91f8df982c3d0d479d650c6ca19310a994eccdaa79a4af3916b7d'
            '2aa843e0d5cd342e8008280bc9d97a8e503c1c3c5fe9e418cdbd203f959733d5')

prepare() {
  cd "$srcdir"/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/skip-broken-cmake-rc.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  # TODO: package more needed libraries instead of including them.
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DENABLE_TESTS=OFF \
      -DENABLE_QT=OFF \
      -DENABLE_GTK=ON \
      -DUSE_SYSTEM_EVENT2=ON \
      -DUSE_SYSTEM_DHT=OFF \
      -DUSE_SYSTEM_MINIUPNPC=ON \
      -DUSE_SYSTEM_NATPMP=OFF \
      -DUSE_SYSTEM_UTP=OFF \
      -DUSE_SYSTEM_B64=OFF \
      -DWITH_CRYPTO=openssl \
      ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}

  make install DESTDIR="${pkgdir}"
}
